package com.noteam.chinamapview.util;

import com.noteam.chinamapview.ChinaMapView;
import com.noteam.chinamapview.moudle.ChinaMapModel;

import java.util.HashMap;

/**
 * ProvideMoudle
 *
 * @author jjy
 * @since 2021-05-10
 */
public class ColorChangeUtil {
    /**
     * 省份数据
     */
    private static final String[] PROVINCE_DATAS = {"北京_17.58_6.87_427_1435", "天津_7.29_11.75_376_1208",
        "河北_-2.84_9.54_414_1090_431_1141", "山西_26.53_60.18_331_934_370_937",
        "内蒙古_-19.44_-16.02_576_1640_266_725", "山东_-0.06_-0.04_404_1105_420_1149",
        "辽宁_-2.82_1.37_275_926_306_1105", "吉林_-2.8_-1.91_221_664_274_853",
        "黑龙江_27.24_23.19_275_832_294_893", "上海_-14.35_-6.65_288_965_345_1178",
        "江苏_-11.3_-6.26_407_1191_444_1293", "浙江_18.97_-3.33_481_1038_521_1122",
        "安徽_-13.9_-9.1_411_1306_418_1332", "福建_-34.11_-47.99_254_591_254_591",
        "江西_25.16_20.76_364_1075_367_1081", "河南_10.46_13.25_292_887_308_929",
        "湖北_2.29_9.56_300_1062_308_1120",
        "湖南_-39.49_-31.74_171_694_161_689",
        "重庆_-36.36_-24.38_167_735_187_840",
        "四川_-9.82_6.23_267_821_0_0",
        "广东_-31.2_-33.13_250_705_256_719",
        "广西_0_0_0_0_0_0",
        "海南_-22.71_-22.3_429_1171_469_1282",
        "贵州_18.03_23.46_173_446_0_0",
        "云南_-14.46_-0.55_277_684_83_236",
        "陕西_5.31_0.35_481_1322_513_1405",
        "甘肃_88.44_27.21_224_681_302_923",
        "青海_757.91_646.46_322_861_398_1085",
        "宁夏_-27.58_-34.42_299_840_313_880",
        "新疆_-6.28_-5.69_175_454_301_1017",
        "西藏_25.18_31.82_210_643_0_0",
        "香港_0_0_0_0_0_0",
        "澳门_0_0_0_0_0_0",
        "台湾_0_0_0_0_0_0"
    };

    /**
     * 颜色数据
     */
    private static final String[] COLORSTRINGS = {"#D50D0D,#DC5754,#E98683,#F8CECF,#D3DFD5,#8DB093,#5E9361,#1C6620",
        "#D50D0D,#DC5754,#E98683,#F8CECF,#D3DFD5,#8DB093,#5E9361,#1C6620",
        "#E9EFF4,#D4E1EA,#BDD1DF,#A8C2D5,#92B3CA,#7DA4C0,#6794B5,#5185AB,#3B76A0",
        "#EAEFF5,#D5E0E9,#BFCFDE,#A6C0D8,#92B2CE,#7CA5C1,#6792B6,#4F85AE,#3E759B,#256796"};

    /**
     * 颜色区域值
     */
    private static final String[] TEXTSTRINGS = {"~-30,-30~-20,-20~-10,-10~0,0~10,10~20,20~30,30~",
        "~-30,-30~-20,-20~-10,-10~0,0~10,10~20,20~30,30~",
        "150~,200~,250~,300~,350~,400~,450~,500~,550~",
        "400~,500~,600~,700~," + "800~,900~,1000~,1100~,1200~,1300~,"};

    /**
     * 统计标题
     */
    private static final String[] NAMESTRINGS = {"发电量增长率", "累计增长率", "发电利用小时", "累计利用小时"};
    private static HashMap<String, String> hashmap;
    private static final int MINVALUE = -30;
    private static final int AVERAGE = 10;
    private static final int MIN_POWER_USER_TIME = 150;
    private static final int POWER_TOTAL_USER_TIME = 400;
    private static final int POWER_USER_AVERAGE = 50;
    private static final int POWER_TOTAL_AVERAGE = 100;
    private static final int TYPE_TWO = 2;
    private static final int TYPE_THREE = 3;

    private ColorChangeUtil() {
    }

    /**
     * 获取省份数据
     *
     * @return 省份数据
     */
    public static String[] getProvinceDatas() {
        return PROVINCE_DATAS.clone();
    }

    /**
     * 获取颜色数据
     *
     * @return 颜色数据
     */
    public static String[] getColorstrings() {
        return COLORSTRINGS.clone();
    }

    /**
     * 获取文字数据
     *
     * @return 文字数据
     */
    public static String[] getTextstringS() {
        return TEXTSTRINGS.clone();
    }

    /**
     * 获取统计类型
     *
     * @return 统计类型
     */
    public static String[] getNamestrings() {
        return NAMESTRINGS.clone();
    }

    /**
     * 改变map颜色
     *
     * @param mapView
     * @param mymap
     * @param type
     */
    public static void changeMapColors(ChinaMapView mapView, ChinaMapModel mymap, String type) {
        if (hashmap == null) {
            HashMap<String, String> hashmap = new HashMap();
            for (int index = 0; index < getProvinceDatas().length; index++) {
                hashmap.put(getProvinceDatas()[index].split("_")[0], getProvinceDatas()[index]);
            }
            ColorChangeUtil.hashmap = hashmap;
        }
        switch (type) {
            case "发电量增长率":
                getMapColors(mapView, mymap, MINVALUE, AVERAGE, 0);
                break;
            case "累计增长率":
                getMapColors(mapView, mymap, MINVALUE, AVERAGE, 1);
                break;
            case "发电利用小时":
                getMapColors(mapView, mymap, MIN_POWER_USER_TIME, POWER_USER_AVERAGE, TYPE_TWO);
                break;
            case "累计利用小时":
                getMapColors(mapView, mymap, POWER_TOTAL_USER_TIME, POWER_TOTAL_AVERAGE, TYPE_THREE);
                break;
            default:
        }
    }

    /**
     *
     * getMapColors
     *
     * @param mapView mapView对象
     * @param mymap mymapmoudle
     * @param min min
     * @param average average
     * @param type type
     */
    public static void getMapColors(ChinaMapView mapView, ChinaMapModel mymap, float min, float average, int type) {
        mapView.setTouchPaints(hashmap, min, average, type);
    }
}
